package com.ncloud.resman.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.resman.entity.DeviceUnit;
import com.ncloud.resman.mapper.DeviceUnitMapper;
import com.ncloud.resman.service.DeviceUnitService;
import com.ncloud.resman.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by shiqiang on 2017/8/15.
 */
@Service
public class DeviceUnitServiceImpl implements DeviceUnitService{
    @Autowired
    private DeviceUnitMapper deviceUnitMapper;
    @Autowired
    private SequenceService sequenceService;

    @Override
    public int insertDeviceUnit(DeviceUnit deviceUnit) {
        if(deviceUnit.getId()== null){
            Long id = sequenceService.getSequence("unit_id_seq");
            deviceUnit.setId(id);
        }
        deviceUnit.setUseTag("1");
        return deviceUnitMapper.insertDeviceUnit(deviceUnit);
    }

    @Override
    public int deleteDeviceUnit(Long deviceId) {
        return deviceUnitMapper.deleteDeviceUnit(deviceId);
    }

    @Override
    public List<JSONObject> getDeviceUnitById(Long deviceId) {
        return deviceUnitMapper.getDeviceUnitById(deviceId);
    }

	@Override
	public List<DeviceUnit> getDeviceUnitSnNum(String snNum) {
		return deviceUnitMapper.getDeviceUnitBySnNum(snNum);
	}

    @Override
    public List<DeviceUnit> getDeviceUnitByType(Long deviceId, String unitType) {
        return deviceUnitMapper.getDeviceUnitByType(deviceId,unitType);
    }

    @Override
    public List<DeviceUnit> getDeviceUnitByIpmi(String ipmiAddr,String unitType) {
        return deviceUnitMapper.getDeviceUnitByIpmi(ipmiAddr,unitType);
    }
}
